package com.qf.cx.simplenms.link.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;


public class OpSpec {
	
	/** logger. */
	private static final Logger LOG = Logger.getLogger(OpSpec.class);
	
	private static final int minAntId = 1;
	private static final int maxAntId = 4;
	private static final int maxTmMask = 2;
	private static final int maxOpNum = 8;
	
	/**set of antenna id*/
	private Set<Integer> antenna = new HashSet<Integer>();
	
	/**list of tag memory mask*/
	private List<TagMemoryMask> tmMask = new ArrayList<TagMemoryMask>();
	
	/**list of op info,include ReadOpSpec, WriteOpSpec*/
	private List<Object> opInfo = new ArrayList<Object>();
	
	public OpSpec() {
		super();
		//LOG.setLevel(Level.DEBUG);
		// TODO Auto-generated constructor stub
	}
    
	public boolean addAntenna(int antId)
	{
		if( (antId < minAntId) || (antId > maxAntId))
		{
			LOG.error("antenna id is out of range, id = " + antId);	
			return false;
		}
		
		this.antenna.add(antId);
		
		LOG.debug("add antenna success, id = " + antId);			
		
		return true;
	}
	
	public boolean deleteAntenna(int antId)
	{
		if( (antId < minAntId) || (antId > maxAntId))
		{
			LOG.error("antenna id is out of range, id = " + antId);	
			return false;
		}		
		
		if(this.antenna.contains(antId))
		{
			this.antenna.remove(antId);
		}
		else
		{
			LOG.error("antenna id no exist, id = " + antId);				
		}
		
		LOG.debug("delete antenna success, id = " + antId);	
		
		return true;
	}
	
	public void deleteAllAntenna()
	{
		this.antenna.clear();
	}
	
	
	public Set<Integer> getAntenna() {
		return antenna;
	}

	public List<TagMemoryMask> getTmMask() {
		return tmMask;
	}

	public List<Object> getOpInfo() {
		return opInfo;
	}

	public boolean addTagMask(TagMemoryMask tmMask)
	{
		if(this.tmMask.size() >= maxTmMask)
		{
			LOG.error("tag memory masks is full! max size is " + maxTmMask);
			return false;
		}
		
		this.tmMask.add(tmMask);
		
		LOG.debug("add tag memory masks success!");
		
		return true;
	}
	
	public void deleteAllTagMask()
	{
		tmMask.clear();
	}
	
	public boolean addRwOpSpec(Object opInfo)
	{
		if( !(opInfo instanceof ReadOpSpec) && (!(opInfo instanceof WriteOpSpec)))
		{
			LOG.error("opspec calss is invalid ");
			return false;			
		}
		
		if(this.opInfo.size() >= maxOpNum)
		{
			LOG.error("op spec list is full! max size is " + maxOpNum);
			return false;
		}	
		
		this.opInfo.add(opInfo);
		
		LOG.debug("add op spec success!");
		
		return true;
	}
	
	public void deleteAllRwOpSpec()
	{
		opInfo.clear();
	}

	@Override
	public String toString() {
		return "OpSpec [antenna=" + antenna + ", tmMask=" + tmMask + ", opInfo=" + opInfo + "]";
	}
	
}
